#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import rospy
from ros_demo.srv import AddTwoInts, AddTwoIntsResponse

def add_two_ints(req):
    """服务回调函数"""
    rospy.loginfo(f"服务请求: {req.a} + {req.b}")
    return AddTwoIntsResponse(req.a + req.b)

def add_two_ints_server():
    # 初始化ROS节点
    rospy.init_node('add_two_ints_server_py')
    
    # 创建服务服务器
    s = rospy.Service('add_two_ints', AddTwoInts, add_two_ints)
    
    rospy.loginfo("Python服务服务器启动，等待加法请求...")
    
    # 进入循环，等待服务请求
    rospy.spin()

if __name__ == "__main__":
    add_two_ints_server()
